﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QLSX.BO;
using QLSX.Common;

namespace QLSX
{
    public partial class frmCauHinh : Form
    {
        ThanhPhan duong = ThanhPhan.SelectThanhPhanById((int)Constant.MaThanhPhan.DUONG);
        ThanhPhan bot = ThanhPhan.SelectThanhPhanById((int)Constant.MaThanhPhan.BOT);
        ThanhPhan nuoc = ThanhPhan.SelectThanhPhanById((int)Constant.MaThanhPhan.NUOC);

        public frmCauHinh()
        {
            InitializeComponent();
        }

        private void frmCauHinh_Load(object sender, EventArgs e)
        {
            LoadCauHinhMacDinh();
        }

        private void LoadCauHinhMacDinh()
        {
            txtDuong.Text = duong.GiaTriMacDinh.ToString();
            lblDonViDuong.Text = duong.DonVi;

            txtBot.Text = bot.GiaTriMacDinh.ToString();
            lblDonViBot.Text = bot.DonVi;

            txtNuoc.Text = nuoc.GiaTriMacDinh.ToString();
            lblDonViNuoc.Text = nuoc.DonVi;
        }

        private ThanhPhan SelectThanhPhanByThanhPhanId(int p)
        {
            throw new NotImplementedException();
        }

        private void btnLuu_Click(object sender, EventArgs e)
        {
            try
            {
                ThanhPhan.UpdateThanhPhan_GiaTriMacDinh((int)Constant.MaThanhPhan.DUONG, Double.Parse(txtDuong.Text));

                ThanhPhan.UpdateThanhPhan_GiaTriMacDinh((int)Constant.MaThanhPhan.BOT, Double.Parse(txtBot.Text));

                ThanhPhan.UpdateThanhPhan_GiaTriMacDinh((int)Constant.MaThanhPhan.NUOC, Double.Parse(txtNuoc.Text));

                MessageBox.Show("Chỉnh sửa thành công");
            }
            catch(Exception exp)
            {
                MessageBox.Show("Nhập số cho giá trị");
            }
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }
    }
}
